{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <!--<div class="col-sm-12">-->
                <!--<div class="layui-form layui-form-item">-->
                <!--<div class="layui-col-md6 layui-input-inline">-->
                <!--<input type="text" id="key" class="layui-input search" name="key" value="" placeholder="省级管理员名称/厂家名称"/>-->
                <!--</div>-->
                <!--<div class="layui-input-inline">-->
                <!--<input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="开始日期" />-->
                <!--</div>-->
                <!--<div class="layui-input-inline">-->
                <!--<input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="结束日期" />-->
                <!--</div>-->
                <!--<div class="layui-input-inline">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>-->
                <!--<button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                <div class="input-group" >
                <button class="btn btn-primary" type="button" onclick="wk.href('{:url('add')}');">
                <i class="fa fa-plus"></i> 添加售后管理
                </button>
                </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="giveQx({{d.instructions_id}})" class="btn btn-info btn-xs m-r-xs" title="分配用户"><i class="fa fa-unlock"></i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.instructions_id}}','{:url('del')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o"></i></a>
                        {{# if(d.instructions_type == 1){ }}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# }else if(d.instructions_type == 2){ }}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# }else if(d.instructions_type == 3){ }}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# }else if(d.instructions_type == 4){ }}
                        <a href="{{d.instructions_url}}"  download class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# }else if(d.instructions_type == 5){ }}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# }else if(d.instructions_type == 6){ }}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>
                        {{# } else {}}
                        <a href="{{d.instructions_url}}"  class="btn btn-primary  btn-xs m-r-xs">下载</a>

                        {{# } }}
                    </script>
                    <script type="text/html" id="instructions_type">
                        {{# if(d.instructions_type == 1){ }}
                        <span style="color:#ec4758">表格</span>
                        {{# }else if(d.instructions_type == 2){ }}
                        <span style="color:#ec4758">文档</span>
                        {{# }else if(d.instructions_type == 3){ }}
                        <span style="color:#ec4758">PPT</span>
                        {{# }else if(d.instructions_type == 4){ }}
                        <span style="color:#ec4758">PDF</span>
                        {{# }else if(d.instructions_type == 5){ }}
                        <span style="color:#ec4758">图片</span>
                        {{# }else if(d.instructions_type == 6){ }}
                        <span style="color:#ec4758">视频</span>
                        {{# } else {}}
                        <span style="color:#ec4758">音频</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="instructions_status">
                        {{# if(d.instructions_status == 1){ }}
                        <span style="color:#ec4758">说明书</span>
                        {{# }else if(d.instructions_status == 2){ }}
                        <span style="color:#ec4758">安装调试</span>
                        {{# }else if(d.instructions_status == 3){ }}
                        <span style="color:#ec4758">故障维修</span>
                        {{# }else if(d.instructions_status == 4){ }}
                        <span style="color:#ec4758">保养视频</span>
                        {{# }else if(d.instructions_status == 5){ }}
                        <span style="color:#ec4758">产品信息</span>
                        {{# } else {}}
                        <span style="color:#ec4758">厂家信息</span>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="zTreeDemoBackground left" style="display: none" id="role">
    <input type="hidden" id="nodeid">
    <div class="form-group">
        <div class="col-sm-5 col-sm-offset-2">
            <ul id="treeType" class="ztree"></ul>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-4 col-sm-offset-4" style="margin-bottom: 15px">
            <input type="button" value="确认" class="btn btn-primary btn-block" id="postform"/>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("instructions/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 80, title: '序号'}
                , {field: 'instructions_id', width: '', title: 'ID', align: 'center'}
                , {field: 'instructions_name', width: '', title: '文件名称',  align: 'center'}
                , {field: 'instructions_status', width: '', title: '是否分配', align: 'center'}
                , {field: 'instructions_type', width: '', title: '广告类型', align: 'center',toolbar:'#instructions_type'}
                , {field: 'instructions_status', width: '', title: '售后类型', align: 'center',toolbar:'#instructions_status'}
                , {field: 'instructions_time', width: '', title: '创建时间', align: 'center'}
                , {fixed: 'right', width: 150, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("user_state")}',obj);
        });

        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDelUser')}");
            }
            ,forbiddenAll: function(){
                //批量禁用
                wk.batchForbidden(getIds(),2,"{:url('forbiddenAdmin')}");
            }
            ,usingAll: function(){
                //批量启用
                wk.usingAll(getIds(),1,"{:url('usingAdmin')}");
            }
            ,excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('#layuiForm').serialize(),"{:url('excelAdmin')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['instructions_id'])
            });
            return ids;
        }
    });
</script>
<script type="text/javascript">
    zNodes = '';
    var index = '';
    var index2 = '';
    //分配权限
    function giveQx(id){
        $("#nodeid").val(id);
        //加载层
        index2 = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        //获取权限信息
        $.getJSON('./giveAccess', {'type' : 'get', 'id' : id}, function(res){
            layer.close(index2);
            if(res.code == 200){
                zNodes = JSON.parse(res.data);  //将字符串转换成obj

                //页面层
                var index = wk.layer_show1("用户分配",$('#role'),400);
                //设置位置
                layer.style(index, {
                    top: '5%'
                });

                //设置zetree
                var setting = {
                    view: {
                        dblClickExpand: true,//是否双击展开
                        showLine: true,//设置为显示或隐藏线条
                        selectedMulti: false,//设置是否允许选择多个节点
                        expandSpeed: "slow",//节点展开动画速度  "slow"、 "normal"、"fast"
                        showIcon: true,//设置为显示或隐藏节点图标
                        // fontCss : {color:"red"},//个性化的文本样式
                    },
                    check:{
                        enable:true,//设置为接受简单数据格式
                        chkStyle: "checkbox",//复选框类型
                        chkboxType: { "Y": "ps", "N": "ps" }//当一个节点被选中或未选中时，控制其父节点及其子节点自动选中或取消选中p:父节点  s:子节点
                    },
                    data: {
                        simpleData: {
                            enable: true,//将zTree的节点设置为接受简单数据格式
                        }
                    }
                };

                $.fn.zTree.init($("#treeType"), setting, zNodes);
                var zTree = $.fn.zTree.getZTreeObj("treeType");
                zTree.expandAll(true);

            }else if(res.code == 100){
                wk.error(res.msg);
                return false;
            }
        });
    }

    //确认分配权限
    $("#postform").click(function(){
        var zTree = $.fn.zTree.getZTreeObj("treeType");
        var nodes = zTree.getCheckedNodes(true);
        var NodeString = '';

        $.each(nodes, function (n, value) {

            if(n>0){
                NodeString += ',';
            }
            if(value.pId!= null){
                NodeString += value.id;
            }
        });
        var id = $("#nodeid").val();
        //写入库
        $.post('./giveAccess', {'type' : 'give', 'id' : id, 'rule' : NodeString}, function(res){
            layer.closeAll();
            if(res.code == 200){
                wk.success(res.msg);layui.table.reload('testReload');
            }else if(res.code == 100){
                wk.error(res.msg);
                return false;
            }

        }, 'json')
    })
</script>
</body>
</html>